import baseapi from '@/api/base'
import { getDataByParameter, getObjetInfoByPid, getCountByParameter, saveObjetInfo, deleteObjetInfo, postInfo } from '@/utils/baserequest'
import storage from 'store'

const Base64 = require('js-base64').Base64

const api = {
  appContext: baseapi.biz,
  appAppId: baseapi.biz_app,
  appServer: 'zhuCeZheng',
  //医院端
  getByConditions_h: 'productLicense/by/findLikeExample',
  getByConditionsCount_h: 'productLicense/countLikeExample/',
  //供应商端 
  getByConditions: 'zhuCeZheng/by/findLikeExample',
  getByConditionsCount: 'zhuCeZheng/countLikeExample/',
  // 推送注册证
  pushedRegisLicense: 'zhuCeZheng/pushNew/',
  // 审核注册证
  auditLicense: 'zhuCeZheng/review',
  
  // 查询已推送注册证
  getpushedByConditions: 'zhuCeZhengTuiSongJiLu/by/findLikeExample',

  deleteInfo:''


}
export default api

//多条件查询
export function getByConditions(parameter, pagination, headers) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org'),
    authOption: (headers && headers.authOption && headers.authOption !== 'undefined') ? headers.authOption : '1'
  }
  const pa = {
    example: Base64.encode(JSON.stringify(Object.assign( parameter,  {orgPid: storage.get('org') }))),
    pageSize: pagination.pageSize,
    currentPage: pagination.current,
    sidx: "",
    order: "0"
  }
  const url = api.appContext + api.getByConditions
  const allheaders = appIdHeaders
  return getDataByParameter(url, pa, allheaders)
}
//多条件查询列表条数
export function getByConditionsCount(parameter, headers) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org'),
    authOption: (headers && headers.authOption && headers.authOption !== 'undefined') ? headers.authOption : '1'
  }
  const example = Object.assign( parameter,  {orgPid: storage.get('org') })
  const url = api.appContext + api.getByConditionsCount
  const allheaders = appIdHeaders
  return getCountByParameter(url, Base64.encode(JSON.stringify(example)), allheaders)
}
//多条件查询
export function getByConditions_h(parameter, pagination, headers) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org'),
    authOption: (headers && headers.authOption && headers.authOption !== 'undefined') ? headers.authOption : '1'
  }
  const pa = {
    example: Base64.encode(JSON.stringify(Object.assign( parameter,  {orgPid: storage.get('org') }))),
    pageSize: pagination.pageSize,
    currentPage: pagination.current,
    sidx: "",
    order: "0"
  }
  const url = api.appContext + api.getByConditions_h
  const allheaders = appIdHeaders
  return getDataByParameter(url, pa, allheaders)
}
//多条件查询列表条数
export function getByConditionsCount_h(parameter, headers) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org'),
    authOption: (headers && headers.authOption && headers.authOption !== 'undefined') ? headers.authOption : '1'
  }
  const example = Object.assign( parameter,  {orgPid: storage.get('org') })
  const url = api.appContext + api.getByConditionsCount_h
  const allheaders = appIdHeaders
  return getCountByParameter(url, Base64.encode(JSON.stringify(example)), allheaders)
}
//新增和修改
export function saveInfo(parameter) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org')
  }
  const url = api.appContext + api.appServer + '/'
  const allheaders = appIdHeaders
  return saveObjetInfo(url, parameter, allheaders)
}

export function deleteInfo(parameter) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org')
  }
  const url = api.appContext + api.appServer + '/'
  const allheaders = appIdHeaders
  return deleteObjetInfo(url, parameter, allheaders)
}

//上传厂家证照
export function saveSellerLicense(parameter) { 
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org')
  }
  const url = api.appContext + api.appServer + '/' 
  const allheaders = appIdHeaders
  return saveObjetInfo(url, parameter, allheaders)
}

// 通过pid得到厂家证照
export function getLicenseByPid(parameter, headers) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org')
  }
  const url = api.appContext + api.appServer
  const allheaders = appIdHeaders
  return getObjetInfoByPid(url, parameter, allheaders)
}

// 通过pid得到信息通用请求:get请求getLicenseByPid
export function getInfoByPid(parameter, headers) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org')
  }
  const url = api.appContext + api.appServer
  const allheaders = appIdHeaders
  return getObjetInfoByPid(url, parameter, allheaders)
}

// 推送注册证
export function pushRegisLicense(parameter) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org')
  }
  const url = api.appContext + api.pushedRegisLicense
  const allheaders = appIdHeaders
  return postInfo(url, parameter, allheaders)
}
// 审核注册证
export function auditLicense(parameter) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org')
  }
  const url = api.appContext + api.auditLicense
  const allheaders = appIdHeaders
  return postInfo(url, parameter, allheaders)
}

//
//多条件查询
export function getpushedByConditions(parameter, pagination, headers) {
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org'),
    authOption: (headers && headers.authOption && headers.authOption !== 'undefined') ? headers.authOption : '1'
  }
  const pa = {
    example: Base64.encode(JSON.stringify(Object.assign( parameter,  {orgPid: storage.get('org') }))),
    pageSize: 1000000,
    currentPage: 1,
    sidx: "",
    order: "0"
  }
  const url = api.appContext + api.getpushedByConditions
  const allheaders = appIdHeaders
  return getDataByParameter(url, pa, allheaders)
} 

//通过查询注册证
export function getRegisLicenseByPid(parameter,headers){
  const appIdHeaders = {
    appId: api.appAppId,
    org: storage.get('org'),
    authOption: (headers && headers.authOption && headers.authOption !== 'undefined') ? headers.authOption : '1'
  }
  const url = api.appContext+api.getByConditions
  headers==null?headers={}:''
  const allheaders = Object.assign(headers, appIdHeaders)
  return getDataByParameter(url, parameter, allheaders)
}



